package com.situ.hibernate.util;

import static org.hamcrest.CoreMatchers.nullValue;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {
	private static SessionFactory sessionFactory = null;
	
	static{
		Configuration configuration = new Configuration();
		configuration.configure();//默认加载src/hibernate.cfg.xml
		//创建SessionFactory的工厂对象
		sessionFactory = configuration.buildSessionFactory();
	}
	
	public static Session openSession() {
		//创建Session（代表一个会话，与jdbc中Connection非常像）
		Session session = sessionFactory.openSession();
		 return session;
	}
	
}
